#ifndef __FRUSTUM_H__
#define __FRUSTUM_H__

#include "Point3D.h"
#include "Vector3D.h"
#include "BBox.h"

namespace geom
{
	/** Stores necesary information to model a camera frustum and check for frustum culling */
	class Frustum
	{
		public:
			/** Constructor
			  @param viewPoint Point where the camera is at
			  @param viewDir Direction the camera is looking
			  @param nearPlane Distance of the near plane
			  @param farPlane Distance of the far plane
			  @param horizFOV Field fo view in the horizontal plane
			  @param aspectRatio Aspect ratio for the frustum (width/height) used for calculating the vertical FOV*/
			Frustum(const Point3D & viewPoint, const Vector3D & viewDir, float nearPlane, float farPlane, float horizFOV, float aspectRatio);

			/** Checks if this frustum contains the given point */
			bool contains(const Point3D & p) const;
			/** Checks if this frustum contains the given bounding sphere */
			bool contains(const BSphere & s) const;

		private:
			typedef struct
			{
				Point3D m_p;
				Vector3D m_n;
				float distance(const Point3D &p) const 
				{
					float result = 0;
					for(int i=0;i<3;++i)
						result += m_n.dv[i] * (p.v[i] - m_p.v[i]);
					return result;
				}
			} FrustumPlane;

			FrustumPlane m_planes[6];

	};
}

#endif
